﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Scenes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GameEngine.Camera;
using PvT.Scenes.Screens;
using GameEngine.Managers.IManagers;
using PvT.Entities;
using GameEngine.EntityComponents;
using PvT.Scenes.Factory;
using GameEngine.Utils;

namespace PvT.Scenes
{
    public class GameOverScreen : AbstractGameScreen
    {
        private Texture2D dummyTexture;

        public GameOverScreen(Game game)
            : base(game)
        {
            this.MenuTitle = "Game Over";
            this.dummyTexture = game.Content.Load<Texture2D>("redpicture");
            this.spriteFont = game.Content.Load<SpriteFont>("Fonts/gamefont");
            this.TransitionOnTime = TimeSpan.FromSeconds(2);
            this.TransitionOffTime = TimeSpan.FromSeconds(2);

            // Create our menu entries.
            MenuEntry playGameMenuEntry = new MenuEntry(game, "Start new game");
            MenuEntry exitMenuEntry = new MenuEntry(game, "Exit");

            // Hook up menu event handlers.
            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(playGameMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        #region Handle Input

        public override void PauseAction()
        { }

        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>
        void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            IAudioManager audioManager = (IAudioManager)game.Services.GetService(typeof(IAudioManager));
            audioManager.StopLoopedSound("sound");
            ISceneManager sceneManager = (ISceneManager)game.Services.GetService(typeof(ISceneManager));
            this.isActive = false;
            sceneManager.ClearScenes();
            Scene sceneWrapper;
            (new ConcreteFactory()).GetLevel(game, "", out sceneWrapper);
            sceneManager.PushScene(sceneWrapper);
        }

        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            game.Exit();
        }

        #endregion
    }
}
